import { message, notification } from 'antd';
import Cookies from 'js-cookie';
import * as network from './request';

import { loginPath } from '../../config/request.config';

export { network };
export default {};

export const fetchValidation = (response: any) => {
    switch (response.code) {
        case 0:
            return response;
        case 6:
            message.error(response.msg);
            window.location.href = loginPath;
            return null;
        // case 1:
        //   message.error(response.msg);
        //   return response;
        default:
            message.error(response.msg);
            return null;
    }
};

export const addOrEditValidation = (response: any, params: any) => {
    switch (response.code) {
        case 0:
            return response;
        case 6:
            message.error(response.msg);
            window.location.href = loginPath;
            return null;
        case 1:
            notification.error({
                message: `${params.phone}`,
                description: `${response.msg}`
            });
            return null;
        default:
            message.error(response.msg);
            return null;
    }
};
